package com.heima.account.action;

import io.seata.rm.tcc.api.BusinessActionContext;
import io.seata.rm.tcc.api.BusinessActionContextParameter;
import io.seata.rm.tcc.api.LocalTCC;
import io.seata.rm.tcc.api.TwoPhaseBusinessAction;

/**
 * TCC接口：声明三个方法  Try  Confirm Cancel
 */
@LocalTCC
public interface AccountAction {


    /**
     *  @TwoPhaseBusinessAction注解   name属性 try方法名称-资源检测预留    commitMethod属性：确认方法  rollbackMethod属性：取消补偿方法
     *  @BusinessActionContextParameter  通过Seata提供API 从上下文中获取对应参数
     * @param userId 业务参数 用户ID
     * @param money 业务参数 扣减金额
     */
    @TwoPhaseBusinessAction(name = "deduct", commitMethod = "confirm", rollbackMethod = "cancel")
    public void deduct(@BusinessActionContextParameter(paramName = "userId") Integer userId, @BusinessActionContextParameter(paramName = "money") Integer money);


    /**
     * 确认方法
     * @param context Seata上下文环境
     * @return
     */
    public boolean confirm(BusinessActionContext context);


    /**
     * 取消方法：补偿方法
     * @param context
     * @return
     */
    public boolean cancel(BusinessActionContext context);

}
